﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace DynCMS.NET.Infrastructure.IOC.Windsor.Impl
{
    internal class DependencyResolver : IOC.MVC.DependencyResolver
    {
        public DependencyResolver(Castle.Windsor.WindsorServiceProvider provider)
        {
            this._serviceProvider = provider;
        }

        public override object GetService(Type serviceType)
        {
            if ((this._serviceProvider as Castle.Windsor.WindsorServiceProvider).Kernel.HasComponent(serviceType))
            {
                return base.GetService(serviceType);
            }
            else
            {
                return Activator.CreateInstance(serviceType);
            }
        }

        public override IEnumerable<object> GetServices(Type serviceType)
        {
            var array = (this._serviceProvider as Castle.Windsor.WindsorServiceProvider).Kernel.ResolveAll(serviceType);
            return array.Cast<object>().AsEnumerable();
        }
    }
}